<?php
require('quest.api.php');
require('user.api.php');
require('checkin.api.php');

$query = $_REQUEST["query"];

if(_LQ_DEBUG_ ){
	error_log('query: '.var_export($query, true));	
}

// API CALLS //
switch($query['request']) {
	case "get_users":
		$result = getUsers();
		break;
	case "signup":
		$result = newUser($query["user_nm"], $query["user_pw"]);
		break;
	case "verify_user":
		$result = verifyUser($query["user_nm"], $query["user_pw"]);
		break;
	case "get_quests":
		$result = getQuests($query['user_id']);
		break;
	case "register_quest":
		$result = registerQuest($query['user_id'], $query['quest_nm'], 
					$query['quest_type'], $query['quest_freq'], $query['quest_exp_date']);
		break;
	case "delete_quest":
		$result = deleteQuest($query['quest_id']);
		break;
	case "update_checkin":
		$result = updateCheckin($query['quest_id']);
		break;		
	case "cancel_checkin":
		$result = cancelCheckin($query['quest_id']);
		break;
	default:
		$result = json_encode( array("error" => "Unknown API request.", 
				"debug_info"=> var_export($_REQUEST["query"])))	;
}

// Output Response //
print($result);

?>